<?php
$css_path = "layout/css";
$js_path = "layout/js";
$images_path = "layout/images";
$root_dir = "/p02/";
$root_url = 'http://' . $_SERVER['HTTP_HOST'];
$root_link = $root_url . '/';
$title = 'Journal';

include dirname(__FILE__) . '/layers/bll/journal_detail_bll.php';

if(!empty($_GET['id'])) {
    $journal_id = $_GET['id'];
    $journal = loadJournal($journal_id);
    $journal_sub_detail = loadAllJournalSubDetByJournalID($journal_id);
    if (!empty($journal_sub_detail['CategoryID'])) {
        $category = loadCategory($journal_sub_detail['CategoryID']);
    }
    $categories = loadAllCategoriesByJournalID($journal_id);
    $papers_archive = load_all_archive_by_journal_id($journal_id);
    
} else if(!empty($_GET['cat_id'])) {
    $category_id = $_GET['cat_id'];
    $category = loadCategory($category_id);
    $journal_id = $category['JournalID'];
    $journal = loadJournal($journal_id);
    $journal_sub_detail = loadAllJournalSubDetByCatID($category_id);
    $categories = loadAllCategoriesByJournalID($journal_id);
    $papers_archive = load_all_archive_by_journal_id($journal_id);
} else if (!empty($_GET['p_journal_id'])) {
    if (!empty($_GET['month'])) {
        $month = $_GET['month'];
    }
    if (!empty($_GET['year'])) {
        $year = $_GET['year'];
    }
    $journal_id = $_GET['p_journal_id'];
    $journal = loadJournal($journal_id);
    $papers = loadAllPapersByJournalIDnDated($journal_id, $month, $year);
    $categories = loadAllCategoriesByJournalID($journal_id);
    $papers_archive = load_all_archive_by_journal_id($journal_id);
} else if (!empty($_GET['paper_id'])) {
    $paper_id = $_GET['paper_id'];
    $paper = loadPapersById($paper_id);
    $journal_id = $paper['JournalID'];
    $journal = loadJournal($journal_id);
    $categories = loadAllCategoriesByJournalID($journal_id);
    $papers_archive = load_all_archive_by_journal_id($journal_id);
}

?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="Content-type" value="text/html; charset=UTF-8" />
        <title><?php echo $title; ?> - Tesdo</title>
        <link href="<?php echo $root_link ?>layout/css/chromestyle4.css" rel="stylesheet" />
        <link href="<?php echo $root_link ?>layout/css/common.css" rel="stylesheet" />
        <script src="<?php echo $root_link ?>layout/js/chrome.js"></script>
        <link href="<?php echo $root_link ?>layout/images/favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <meta name="viewport" content="width=device-width" />
    </head>
    <body>
        <?php require_once dirname(__FILE__) . '/includes/header.php'; ?>

        <!-- Body -->
        <div id="body">
            <section class="content-wrapper main-content clear-fix">
                
                <div class="DetailPage">
                    <hgroup class="title">
                        <h1>
                            <span id="MainContent_lblTitle"><?php echo $journal['Title']; ?></span></h1>
                        <h2></h2>
                    </hgroup>
                    <div class="LeftArea">
                        <div id="left_menu">

                            <div>
                                <table id="MainContent_dlcatList" cellspacing="0" style="border-collapse:collapse;">
                    <tbody>
                            <?php
                            foreach ($categories as $i => $item) {
                            ?>
                        <tr>
                                <td>
                                    <ul>
                                        <li><a href="journal_detail.php?cat_id=<?php echo $item['CategoryID']; ?>"><?php echo $item['Title']; ?></a></li>
                                    </ul>
                                </td>
                        </tr>
                            <?php
                            }
                            ?>
                    
            </tbody></table>
                            </div>
                        </div>
                    </div>
                    <article class="CenterArea">
                        <img src="<?php echo $root_link ?>layout/images/journal_images/<?php echo $journal['Photo']; ?>" id="MainContent_imgJournal">
                        <b>Print ISSN:    </b>
                        <span id="MainContent_lblPrintISSN"><?php echo $journal['PrintISSN']; ?></span><br>
                        <br>
                        <b>Online ISSN:   </b>
                        <span id="MainContent_lblOnlineISSN"><?php echo $journal['OnlineISSN']; ?></span><br>
                        <br>
                        <span id="MainContent_lblPublish"></span><br>
                        <span id="MainContent_lblShortDescription"></span><br>
                        <br clear="All">

                        <?php
                        if(!empty($_GET['cat_id']) || !empty($_GET['id'])) {
                        ?>
                        <h3>
                            <span id="MainContent_lblCategory"><?php if (!empty($journal_sub_detail['CategoryID'])) {echo $category['Title'];} ?></span></h3>
                        <p>
                            <span id="MainContent_lblDescription"></span></p><?php echo $journal_sub_detail['Description']; ?>
                        <?php
                        }
                        ?>
                        
                        <?php
                        if(!empty($_GET['p_journal_id'])) {
                            foreach ($papers as $i => $item) {
                        ?>
                        <table id="MainContent_dlPapers" cellspacing="0" cellpadding="0" style="border-collapse:collapse;">
                                <tbody><tr>
                                        <td>
                                            <div class="adsSortDetail">
                                                <div>
                                                   <b> <a href="journal_detail.php?paper_id=<?php echo $item["PaperID"]; ?>" style="color:blue; font-size:14px;"><?php echo $item["Title"]; ?></a></b><br>
                                                    <b>Author:</b> <?php echo $item["Author"]; ?> <br>
                                                    <b>Keywords:</b> <?php echo $item["Keywords"]; ?> <br>
                                                    <b>No of Papers:</b> <?php echo $item["Pages"]; ?><br>
                                                    <hr>
                                                    <b><a href="journal_detail.php?paper_id=<?php echo $item["PaperID"]; ?>" style="color:blue; font-size:14px;">Abstract</a> | <a style="color:blue; font-size:14px;" target="_blank" href="layout/pdf/papers/<?php echo $item["PDFFiles"]; ?>">PDF</a></b>
                                                    <hr>
                                                </div>
                                        </div></td>
                                </tr>
                        </tbody></table>
                        <?php
                            }
                        }
                        ?>
                        
                        <?php
                        if(!empty($_GET['paper_id'])) {
                            $item = $paper;
                        ?>
                        <div id="MainContent_AbstractDeail" class="AbstractDeail">
                            <h4><span id="MainContent_lblAbsTitle"><?php echo $item["Title"]; ?></span></h4>
                            <hr>
                            <h5>Author:</h5>
                           <p> <span id="MainContent_lblAuthor"><?php echo $item["Author"]; ?> </span></p>
                            <h5>Citation:</h5>
                           <p>  <span id="MainContent_lblCitation"><?php echo $item["Citation"]; ?></span></p>
                            <h5>Keywords:</h5>
                          <p>   <span id="MainContent_lblKeywords"><?php echo $item["Keywords"]; ?></span></p>
                            <h5>Article Type:</h5>
                          <p>   <span id="MainContent_lblArticleType"><?php echo $item["ArticleType"]; ?></span></p>
                            <h5>Pages:</h5>
                            <p> <span id="MainContent_lblPages"><?php echo $item["Pages"]; ?></span></p>
                            <h5>DOI:</h5>
                           <p>  <span id="MainContent_lblDOI"><?php echo $item["DOI"]; ?></span></p>
                            <h5>Publisher:</h5>
                           <p>  <span id="MainContent_lblPublisher"><?php echo $item["Publisher"]; ?></span></p>
                            <h5>Abstract:</h5>
                           <p> <span id="MainContent_lblAbstract"><?php echo $item["Abstract"]; ?></span></p>

                            <hr>
                           <a id="MainContent_PDFFile" title="Download PDF File" href="layout/pdf/papers/<?php echo $item["PDFFiles"]; ?>" target="_blank">Download PDF File</a>

                        </div>
                        <?php
                        }
                        ?>
                        
                    </article>
                    <input type="image" name="ctl00$MainContent$ImageButton1" id="MainContent_ImageButton1" class="btnSubmitArticle" src="<?php echo $root_link ?>layout/images/SubmitArticle.png" style="width:190px;">
                    <br>
                    <div class="RightArea">


                        <div id="Archive">
                            <h1>Archive</h1>
                            <div>
                                <table id="MainContent_dlArchive" cellspacing="0" style="border-collapse:collapse;">
                                <tbody>
                                    <tr>
                                        <td>
                                            <ul>
                                                <?php
                                                foreach ($papers_archive as $i => $item) {
                                                ?>
                                                <li>
                                                    <a href="journal_detail.php?p_journal_id=<?php echo $item["journal_id"]; ?>&month=<?php echo $item['month'];; ?>&year=<?php echo $item['year']; ?>">
                                                        <?php echo $item['date_string']; ?>
                                                    </a>
                                                </li>
                                                <?php
                                                }
                                                ?>
                                            </ul>
                                        </td>
                                    </tr>
                                </tbody>
                                </table>


                            </div>
                        </div>
                    </div>
                </div>

            </section>
        </div>
        <!-- End Body -->

        <?php require_once dirname(__FILE__) . '/includes/footer.php'; ?>
    </body>
</html>
